import { defHttp } from '/@/utils/http/axios';
import { createVNode } from 'vue';
import { ExclamationCircleOutlined } from '@ant-design/icons-vue';
import { Modal, message } from 'ant-design-vue';

const API = {
  // 站点列表分页
  page: '/equipment/page',
  // 站点列表
  list: '/equipment/list',
  // 增加equipment
  insert: '/equipment/insert',
  // 编辑equipment
  modify: '/equipment/modify',
  // 删除equipment
  delete: '/equipment/delete',
  // equipment基础信息
  info: '/equipment/info',
  // 计数
  count: '/equipment/count',
}

/**
 * 获取equipment分页列表
 * @param {int} current 当前页
 * @param {int} size 当前页总数
 * @returns
 */
export const equipmentPageApi = async (params) => {
  return await defHttp.get({ url: API.page, params });
}


/**
 * 获取equipment分页列表
 * @param {int} current 当前页
 * @param {int} size 当前页总数
 * @returns
 */
export const equipmentCountApi = async (params) => {
  return await defHttp.get({ url: API.count, params });
}

/**
 * 获取equipment列表
 * @returns
 */
export const equipmentListApi = async (params) => {
  return await defHttp.get({ url: API.list, params });
}

/**
 * 根据ID查询equipment
 * @param {int} id
 * @returns
 */
export const equipmentInfoApi = async (params) => {
  return await defHttp.get({ url: API.info, params });
}

/**
 * 新增equipment数据
 * @param {int} globalIp 公网IP
 * @param {int} globalPort 公网端口
 * @param {int} inIp 内网IP
 * @param {int} inPort 内网端口
 * @param {int} name 名称
 * @param {int} equipmentAccount equipment账号
 * @param {int} equipmentCode equipment编码
 * @param {int} equipmentPassword equipment密码
 * @param {int} staionCode 站点编码
 * @returns
 */
export const equipmentAddApi = async (data) => {
  return new Promise((resolve, reject) => {
    Modal.confirm({
      title: '提示',
      icon: createVNode(ExclamationCircleOutlined),
      content: '确定提交当前数据?',
      centered: true,
      async onOk() {
        await defHttp.post({ url: API.insert, data }).then((res) => {
          resolve(res);
        }).catch((error) => {
          reject(error);
        })
      }, onCancel() {
        message.warning('已取消');
        resolve('')
      },
    });
  })
}

/**
 * 修改equipment数据
 * @param {int} id
 * @param {int} globalIp 公网IP
 * @param {int} globalPort 公网端口
 * @param {int} inIp 内网IP
 * @param {int} inPort 内网端口
 * @param {int} name 名称
 * @param {int} equipmentAccount equipment账号
 * @param {int} equipmentCode equipment编码
 * @param {int} equipmentPassword equipment密码
 * @param {int} stationCode 站点编码
 * @returns
 */
export const equipmentModifyApi = async (data) => {
  return new Promise((resolve, reject) => {
    Modal.confirm({
      title: '提示',
      icon: createVNode(ExclamationCircleOutlined),
      content: '确定提交当前数据?',
      centered: true,
      async onOk() {
        await defHttp.post({ url: API.modify, data }).then((res) => {
          resolve(res);
        }).catch((error) => {
          reject(error);
        })
      }, onCancel() {
        message.warning('已取消');
        resolve('')
      },
    });
  })
}

/**
 * 删除equipment数据接口
 * @param {*} id
 * @returns
 */
export const equipmentDeleteApi = (data) => {
  return new Promise((resolve, reject) => {
    Modal.confirm({
      title: '提示',
      icon: createVNode(ExclamationCircleOutlined),
      content: '确定删除当前设备数据?',
      centered: true,
      onOk() {
        resolve(defHttp.post({ url: API.delete, data }))
      }, onCancel() {
        message.warning('已取消');
        reject();
      },
    });
  })
}